<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
	version="1.0"
	xmlns:php="http://php.net/xsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/navigation.xsl" />
	<xsl:include href="../comments/defaultList.xsl" />
	<xsl:include href="blocks.xsl" />
	<xsl:include href="albumBar.xsl" />

	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/photos/photos.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/photos/tickets.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/comments.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/owner-bar.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/photos.js" />
			<script type="text/javascript" src="{$baseURI}/js/photoTickets.js" />
			<script type="text/javascript" src="{$baseURI}/js/baseComments.js" />
			<script type="text/javascript" src="{$baseURI}/js/photosComments.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />

			<div class="page-header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div class="page-content-wrapper">
				<div class="page-blocks">
					<xsl:call-template name="default-blocks-top" />
					
					<div class="block">
						<div class="header">Другие альбомы пользователя</div>
						<div class="content user-photoalbums-list">
							<xsl:apply-templates select="document(concat('xmodule://photos/getUserAlbums/', response/@album-owner-id, ';', response/@album-id))/data/response" mode="block-user-albums" />
						</div>
						
						<i class="corner-f8-10 tl"></i>
						<i class="corner-f8-10 tr"></i>
						<i class="corner-f8-10 br"></i>
						<i class="corner-f8-10 bl"></i>
					</div>
					
					<div class="block">
						<div class="header">Облако тегов</div>
						<div class="content tags">
							<xsl:apply-templates select="document('xmodule://photos/getTagsCloud')/data/response/tags" mode="block-tags-cloud" />
						</div>
						
						<i class="corner-f8-10 tl"></i>
						<i class="corner-f8-10 tr"></i>
						<i class="corner-f8-10 br"></i>
						<i class="corner-f8-10 bl"></i>
					</div>
				</div>

				<div class="page-content">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	
	
	<!-- RESPONSE -->
	<xsl:template match="response">
		<xsl:apply-templates select="document(concat('xobject://photoalbum/', @album-id))/data/object" mode="album-bar" />
		
		<xsl:apply-templates select="object" />
	</xsl:template>
	
	<xsl:template match="object[@type='photo']">
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		<xsl:param name="userAvatar" select="property[@name='user_avatar']/value" />
		<xsl:param name="rating" select="property[@name='rating']/value" />
		<xsl:param name="allowVote" select="@allow-vote" />
		<xsl:param name="albumId" select="property[@name='album_id']/value" />		
		<xsl:param name="countTags" select="count (property[@name='tags']/value)" />
		<xsl:param name="prevId" select="@previous-id" />
		<xsl:param name="nextId" select="@next-id" />
		<xsl:param name="smallPhotos" select="document(concat('xmodule://photos/getAlbumPhotos/', @id))/data/response/photos" />
		
		<div class="photo-wrapper">
			<xsl:if test="$userGroup != 'guest'">
				<div class="controls">
					<ul>
						<li class="ticket">
							<a href="#" onclick="Tickets.add(); return false;">добавить отметку</a>
						</li>
						<xsl:if test="$userId = property[@name='owner_id']/value">
							<li class="edit">
								<a href="{$baseURI}/photos/edit/{$albumId}?photo[]={@id}">редактировать</a>
							</li>
							<li class="delete">
								<a href="{$baseURI}/photos/delete_photo/{@id}" onclick="if(!confirm('Вы действительно хотите удалить эту фотографию?'))return false;">удалить</a>
							</li>
						</xsl:if>
					</ul>
				</div>
			</xsl:if>
			
			<div class="view">
				<div class="image" id="photo_image">
					<img id="photoimg" alt="" src="{$baseURI}{property[@name='photo']/value}" />
					<div class="tickets" id="photo_tickets">
						<div class="black" />
					</div>
				</div>
			</div>
			
			<div class="info">
				<dl class="add-info">
					<dt>Добавлена</dt>
					<dd>
						<div class="avatar">
							<a href="{$baseURI}/user/{$userLogin}">
								<img alt="{$userLogin}">
									<xsl:attribute name="src">
										<xsl:if test="$userAvatar = ''">
											<xsl:value-of select="concat($baseURI, '/images/default-avatar-small.png')" />
										</xsl:if>
										<xsl:if test="$userAvatar != ''">
											<xsl:value-of select="concat($baseURI, '/thumb_24_24', $userAvatar)" />
										</xsl:if>
									</xsl:attribute>
								</img>
							</a>
						</div>
						
						<a href="{$baseURI}/user/{$userLogin}">
							<xsl:value-of select="$userLogin" />
						</a>
						
						<span class="date">
							<xsl:value-of select="property[@name='date']/value" />
						</span>
					</dd>
				</dl>
				
				<dl class="tags">
					<dt>Теги</dt>
					<dd>
						<xsl:if test="count (property[@name='tags']/value) = 0">
							<xsl:text>пусто</xsl:text>
						</xsl:if>
						<xsl:if test="count (property[@name='tags']/value) != 0">
							<xsl:for-each select="property[@name='tags']/value">
								<a>
									<xsl:attribute name="href">
										<xsl:value-of select="concat ($baseURI, '/photos/tag/', .)" />
									</xsl:attribute>
									<xsl:value-of select="." />
								</a>
								<xsl:if test="position() != $countTags">
									<xsl:text>, </xsl:text>
								</xsl:if>
							</xsl:for-each>
						</xsl:if>
					</dd>
				</dl>
				
				<dl class="rating">
					<dt>Оценка</dt>
					<dd>
						<xsl:apply-templates select="document(concat('xmodule://system/getVoted/', $rating, ';', $allowVote, ';', @type-id, ';', @id, ';0'))/data/response/vote" mode="photo-vote" />
					</dd>
				</dl>
				
				<dl class="tickets">
					<dt>Отметки</dt>
					<dd id="tickets_list" />
				</dl>
			</div>
		</div>
			
		<table class="browser">
			<tbody>
				<tr>
					<td class="button">
						<a class="left" href="#" onclick="return false;" onmouseover="PhotosBrowser.scrollLeft();" onmouseout="PhotosBrowser.stopScroll();" />
					</td>
					<td class="list">
						<div id="photos_browser" />
					</td>
					<td class="button">
						<a class="right" href="#" onclick="return false;" onmouseover="PhotosBrowser.scrollRight();" onmouseout="PhotosBrowser.stopScroll();" />
					</td>
				</tr>
			</tbody>
		</table>
		
		<script type="text/javascript">
			$(document).ready(function () {
				Tickets.photoId = <xsl:value-of select="@id" />;
				Tickets.photoOwnerId = <xsl:value-of select="property[@name='owner_id']/value" />;
				Tickets.load();
				PhotosBrowser.viewingId = <xsl:value-of select="@id" />;
				PhotosBrowser.loadAlbumPhotos(<xsl:value-of select="$albumId" />);
			});
		</script>
		
		
		<a name="comments" />
		
		<div class="comments-header">Комментарии (<xsl:value-of select="property[@name='count_comments']/value" />)</div>
		
		<xsl:apply-templates select="document(concat('xmodule://comments/getComments/photo;', @id))/data/response" mode="comments" />
	</xsl:template>
	
	<!-- PHOTO VOTE -->
	<xsl:template match="vote" mode="photo-vote">
		<xsl:param name="photoId" select="object_id" />
		<xsl:param name="vote" select="mark" />
		<xsl:param name="allow" select="allow" />
		<xsl:param name="rating" select="rating" />
		<xsl:param name="format" select="format" />
		
		<div class="vote-rating corner" id="photo_rating">
			<a class="minus" title="не нравится" href="#">
				<xsl:choose>
					<xsl:when test="$allow = '0' and $vote = ''">
						<xsl:attribute name="onclick">new Error ('Вы не можете проголосовать'); return false;</xsl:attribute>
						<xsl:attribute name="class">minus cant</xsl:attribute>
					</xsl:when>
					<xsl:when test="$allow = '0' and $vote != ''">
						<xsl:attribute name="onclick">new Error ('Повторное голосование запрещено'); return false;</xsl:attribute>
						<xsl:if test="$vote = '0'">
							<xsl:attribute name="class">minus voted</xsl:attribute>
						</xsl:if>
						<xsl:if test="$vote != '0'">
							<xsl:attribute name="class">minus cant</xsl:attribute>
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="onclick">
							<xsl:value-of select="concat ('Photo.vote (', $photoId, ', 0); return false;')" />
						</xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				
				<img src="{$baseURI}/images/post-vote-minus.png" alt="Минус" />
			</a>
			
			<div class="number">
				<xsl:if test="number ($rating) &gt; 0">
					<xsl:attribute name="class">number plus</xsl:attribute>
				</xsl:if>
				<xsl:if test="number ($rating) &lt; 0">
					<xsl:attribute name="class">number minus</xsl:attribute>
				</xsl:if>
				<xsl:value-of select="$format" />
			</div>
			
			<a class="plus" title="нравится" href="#">
				<xsl:choose>
					<xsl:when test="$allow = '0' and $vote = ''">
						<xsl:attribute name="onclick">new Error ('Вы не можете проголосовать'); return false;</xsl:attribute>
						<xsl:attribute name="class">plus cant</xsl:attribute>
					</xsl:when>
					<xsl:when test="$allow = '0' and $vote != ''">
						<xsl:attribute name="onclick">new Error ('Повторное голосование запрещено'); return false;</xsl:attribute>
						<xsl:if test="$vote = '1'">
							<xsl:attribute name="class">plus voted</xsl:attribute>
						</xsl:if>
						<xsl:if test="$vote != '1'">
							<xsl:attribute name="class">plus cant</xsl:attribute>
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="onclick">
							<xsl:value-of select="concat ('Photo.vote (', $photoId, ', 1); return false;')" />
						</xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				
				<img src="{$baseURI}/images/post-vote-plus.png" alt="Плюс" />
			</a>
			
			<i class="tl"></i>
			<i class="tr"></i>
			<i class="br"></i>
			<i class="bl"></i>
		</div>
		
		<!-- 
		<xsl:param name="id" select="object_id" />
		<xsl:param name="vote" select="mark" />
		<xsl:param name="allow" select="allow" />
		<xsl:param name="typeId" select="type_id" />
		<xsl:param name="rating" select="rating" />
		
		<div id="photo_rating">
			<div>
				<a id="photo_vote_plus_{$id}" href="javascript:void(0);" title="&labelLike;">
					<xsl:choose>
						<xsl:when test="$allow = '0' and $vote = ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVote;');</xsl:text>
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-plus-cant.png" alt="" />
						</xsl:when>
						<xsl:when test="$allow = '0' and $vote != ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVoteAgain;');</xsl:text>
							</xsl:attribute>
							<xsl:if test="$vote = '1'">
								<img src="{$baseURI}/images/post-voted-plus.png" alt="" />
							</xsl:if>
							<xsl:if test="$vote != '1'">
								<img src="{$baseURI}/images/post-vote-plus-cant.png" alt="" />
							</xsl:if>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="onclick">
								<xsl:value-of select="concat ('votePhoto (', $id, ', 1);')" />
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-plus.png" alt="" />
						</xsl:otherwise>
					</xsl:choose>
				</a>
			</div>
			<div class="photo_rating_number" id="photo_rating_{$id}">
				<xsl:if test="number ($rating) &gt; 0">
					<xsl:attribute name="class">photo_rating_number plus</xsl:attribute>
					<xsl:text>+</xsl:text>
				</xsl:if>
				<xsl:if test="number ($rating) &lt; 0">
					<xsl:attribute name="class">photo_rating_number minus</xsl:attribute>
				</xsl:if>
				<xsl:value-of select="$rating" />
			</div>
			<div>
				<a id="photo_vote_minus_{$id}" href="javascript:void(0);" title="&labelDislike;">
					<xsl:choose>
						<xsl:when test="$allow = '0' and $vote = ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVote;');</xsl:text>
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-minus-cant.png" alt="" />
						</xsl:when>
						<xsl:when test="$allow = '0' and $vote != ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVoteAgain;');</xsl:text>
							</xsl:attribute>
							<xsl:if test="$vote = '0'">
								<img src="{$baseURI}/images/post-voted-minus.png" alt="" />
							</xsl:if>
							<xsl:if test="$vote != '0'">
								<img src="{$baseURI}/images/post-vote-minus-cant.png" alt="" />
							</xsl:if>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="onclick">
								<xsl:value-of select="concat ('votePhoto (', $id, ', 0);')" />
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-minus.png" alt="" />
						</xsl:otherwise>
					</xsl:choose>
				</a>
			</div>
		</div> -->
	</xsl:template>
	
</xsl:stylesheet>